package com.midian.action.mc.pic;

import java.io.File;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.midian.action.mc.common.AjaxAction;
import com.midian.common.annotation.FunctionAnnotationOverride;
import com.midian.common.exception.BizException;
import com.midian.common.utils.PicUtils;
import com.midian.model.pic.Pic;
import com.midian.service.pic.IPicService;

/**
 * 系统图片上传Action
 */
@Scope("prototype")
@Controller("picAction")
@FunctionAnnotationOverride(isAction = true, auth = "系统图片管理")
public class PicAction extends AjaxAction<Pic> {
	
	/**系统图片实体*/
	private Pic entity;
	/**系统图片实体列表*/
	private List<Pic> rows;
	/**系统图片*/
	private IPicService picService;
	/**图片工具*/
	private PicUtils picUtils;
	
	private File picfile;
	private String  picfileFileName;
	private String picfileContentType;
	
	
	
	public PicUtils getPicUtils() {
		return picUtils;
	}
	@Resource(name="picUtils")
	public void setPicUtils(PicUtils picUtils) {
		this.picUtils = picUtils;
	}
	public File getPicfile() {
		return picfile;
	}
	public void setPicfile(File picfile) {
		this.picfile = picfile;
	}
	public String getPicfileFileName() {
		return picfileFileName;
	}
	public void setPicfileFileName(String picfileFileName) {
		this.picfileFileName = picfileFileName;
	}
	public String getPicfileContentType() {
		return picfileContentType;
	}
	public void setPicfileContentType(String picfileContentType) {
		this.picfileContentType = picfileContentType;
	}
	public Pic getEntity() {
		return entity;
	}
	public void setEntity(Pic entity) {
		this.entity = entity;
	}
	@Resource(name = "picService")
	public void setPicService(IPicService picService) {
		this.service = picService;
		this.picService = picService;
	}
	@Override
	protected Pic dytEntity() {
		if(this.entity == null) {
			this.entity = new Pic();
		}
		return getEntity();
	}
	@Override
	protected void dyEntity(Pic t) {
		setEntity(t);
		
	}
	@Override
	public void setRows(List<Pic> rows) {
		this.rows = rows;
		
	}
	@Override
	public List<Pic> getRows() {
		// TODO Auto-generated method stub
		return rows;
	}
	
	public String saveInfo(){
		System.out.println("----------------------------PicActionSaveInfo-------------------------");
		try {
			String id = dytEntity().getId();
				picUtils.uploadPic(picfile, picfileFileName);
		} catch (BizException e) {
			e.printStackTrace();
			
		}
		return SAVEINFO;
	}

	

}
